package com.kystar.muxplayer.ui;

import android.content.Context;
import android.view.View;
import android.widget.ToggleButton;
import com.kystar.muxplayer.BaseApp;
import com.kystar.muxplayer.R;
import com.kystar.muxplayer.model.PGMConfig;
import com.kystar.muxplayer.protocol.code.set.CS0D_Background;
import com.kystar.muxplayer.protocol.code.set.CS11_PgmConfig;

public class HeadButtonSetting {

    private Context mContext;
    private View mView;
    private ToggleButton freezeBtn;
    private ToggleButton blackBtn;
    private ToggleButton bgBtn;

    public HeadButtonSetting(Context context, View view) {
        mContext = context;
        mView = view;
        freezeBtn = view.findViewById(R.id.pgm_still);
        blackBtn = view.findViewById(R.id.pgm_black_screen);
        bgBtn = view.findViewById(R.id.pgm_background);
        freezeBtn.setOnClickListener(v -> {
            boolean on = freezeBtn.isChecked();
            BaseApp.send(CS11_PgmConfig.createFreeze(on)).subscribe();
        });
        blackBtn.setOnClickListener(v -> {
            boolean on = blackBtn.isChecked();
            BaseApp.send(CS11_PgmConfig.createBlack(on)).subscribe();
        });
        bgBtn.setOnClickListener(v -> {
            boolean on = bgBtn.isChecked();
            BaseApp.send(CS0D_Background.topBg(on)).subscribe(cmd->{},e->{

            });
//            conn.run(p -> p.setBackgroundOnTop(1, on))
//                .onOK(()->sets.config.back = on)
//                .onFail(()->background.setChecked(sets.config.back))
//                .post();
        });

        PGMConfig PGMConfig = BaseApp.getSettings().getPGMConfig();
        blackBtn.setChecked(PGMConfig.isBlack());
        freezeBtn.setChecked(PGMConfig.isFreeze());
    }

}
